<template>
  <div class="container">
    <!-- 产品详情页头部信息 -->
    <ProductHead :content="productMixins.headContent.value" :isLanguage="true" />
    <!-- 保障计划 -->
    <Responsibility :content="productMixins.resContent.value" :sensorsInfo="productMixins.sensorsInfo.value"
      :trialUrl="productMixins.trialUrl.value" :upgradeTip="productMixins.upgradeTip.value"
      :isProductClose="productMixins.isProductClose.value" :router="router" />
    <!-- 悬浮按钮（海报，订单，投保攻略） -->
    <OrderIcon productType="medical" :productCode="productCode" :router="router" />
    <!-- 底部按钮 -->
    <ProductFooter v-if="productMixins.sensorsInfo.value.productCode" :schemePrice="productMixins.schemePrice.value"
      :sensorsInfo="productMixins.sensorsInfo.value" :isNotFetch="isNotFetch" :router="router" />
  </div>
</template>

<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import i18n from '@/lang/m/index' // i18n
import productinfoClass from './productinfoClass'

// 使用类型断言
const t = (key: string) => i18n.global.t(key) as string;

const router = useRouter()


const productCode = ref('DB_BJ_024') // 产品code
const userId = ref('1') // 代理人id

// 在组件挂载时初始化数据
const productMixins = productinfoClass.getInstance({ productCode: productCode.value, userId: userId.value });

onMounted(async () => {
  await productMixins.init()
  productMixins.dealwithProductData()
  console.log(productMixins.headContent.value, 1111)
})

const isRBXYB2024 = computed(() => {
  return ['RBXYB2024', 'LBMTXYB2024'].includes(productMixins.sensorsInfo.value.productCode)
})
// 不需要客户告知书
const isNotFetch = computed(() => {
  const codes = [
    {
      productCode: 'ZLBXYKXYB2024',
      u: '842109'
    }
  ]
  const obj = codes.find(
    (item) => item && item.productCode === productMixins.sensorsInfo.value.productCode
  )
  // 链接如果匹配上userId
  if (obj && obj.u === productMixins.sensorsInfo.value.userid) {
    return true
  }
  return codes.includes(productMixins.sensorsInfo.value.productCode) || isRBXYB2024.value
})


</script>

<style scoped>
@import url(./index.css);
</style>